/**
 *  \file  cant.h
 *
 *  \brief Driver interface to Vector CAN-Cards.
 *
 *  \author Michael J. Hohmann <michael.hohmann@linde-mh.de>
 *
 *    The module cant.c provide an easy interface to access CAN-Card from Vector.
 *
 *  \todo Find Callbackfuntion for received id is done inefficent and should may
 *          replaced by an hashtable.
 *
 */

#ifndef CANT_H_INCLUDED
#define CANT_H_INCLUDED

#ifdef __cplusplus
  extern "C" {
#endif

/*===========================[ public includes   ]============================*/
#include "../cfg/prj.h"
#include <windows.h>
#include "vxlapi.h"

/*===========================[ public defines    ]============================*/

/*===========================[ public datatypes  ]============================*/
/** CAN Message.*/
struct cant_msg
{
   unsigned int id;     /**< Identifier */
   unsigned int dlc;       /**< Data Length Code */
   unsigned char data[8];  /** Data bytes (dependend on DLC not all Databytes are send)*/
   unsigned int rtr;       /** rtr bit - is not supported yet */
};

struct cant_obj;/* forward declaration */

/** Callback Funktion Type */
typedef void* (*cant_rx_callback_function_t)(struct cant_obj * me, struct cant_msg* msg, void** data);

/** Data stored for each install callback funktion.
 * \note It is not expected to use this struct definition outside of this module.
 * \see cant_install_rx_callback()
 */
struct cant_rx_callback
{
   cant_rx_callback_function_t function;
   void *data;
};

/** CANT Object definition. */
struct cant_obj
{
   XLaccess       xlChannelMask;                   /**< Global channelmask (includes all founded channels)     */
   XLaccess       xlPermissionMask;                /**< Global permissionmask (includes all founded channels)  */
   XLportHandle   xlPortHandle;                    /**< Global porthandle (we use only one!)                   */
   unsigned int   BaudRate;                        /**< Default baudrate                                       */
   XLaccess       xlChanMaskTx;                    /**< Channel Mask. Indicate used channel.                   */
   XLhandle       hMsgEvent;                       /**< notification handle for the receive queue              */
   HANDLE         hRXThread;                       /**< thread handle (RX)                                     */
   int            RXThreadRun;                     /**< flag to start/stop the RX thread                       */
   struct cant_rx_callback rx_dispatcher[0x800];   /**< Store callback funtion for all IDs                     */
   struct cant_rx_callback rx_default_callback;    /**< Store default callback                                 */
   U32            serial_number;                   /**< Serial number of the hardware interface that is used   */
   int            channel_index;                   /**< Index of the hardware channel that is used             */
};



/*===========================[ public variables  ]============================*/

/*===========================[ public functions  ]============================*/
struct cant_obj * cant_create(unsigned int BaudRate,CH *name);
RC cant_initialize(struct cant_obj* me, unsigned int BaudRate,CH *name);
RC cant_install_default_rx_callback( struct cant_obj* me, cant_rx_callback_function_t callback, void * data );
RC cant_install_rx_callback( struct cant_obj* me, unsigned int id, cant_rx_callback_function_t callback, void * data );
RC cant_tx(struct cant_obj *me, struct cant_msg *msg);
RC cant_activate(struct cant_obj* me, BO value);
RC cant_close(struct cant_obj *me);
RC cant_flushQueues(struct cant_obj* me);
RC cant_destroy(struct cant_obj *me);

/*============================================================================*/

#ifdef __cplusplus
  }
#endif

#endif  /* CANT_H_INCLUDED */

/*******************************************************************************
*           Copyright 2006 Linde Material Handling. All rights reserved.       *
*******************************************************************************/




























